{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0d158ae2",
   "metadata": {},
   "outputs": [],
   "source": [
    "---------\n",
    "* 日期：2022-10-26 | week10 \n",
    "* 课程：Python\n",
    "* 记录人：杨静雯~\n",
    "---------\n",
    "\n",
    "# 本周学习目标"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f6d6cd60",
   "metadata": {},
   "outputs": [],
   "source": [
    "product_list = [\n",
    "    \"IPHONE 14\",\n",
    "    \"POP MART\",\n",
    "    \"NIKE\",\n",
    "    \"BARBIE\",\n",
    "    \"LEGO\",\n",
    "]\n",
    "\n",
    "1. Alipay = input(\"请输入余额\")\n",
    "   print()\n",
    "    # 情景1；用户输入了商品编号：\n",
    "2. user_choice = input (\"请输入商品编号;\")\n",
    "   # 0,1,2,3\n",
    "3. if 钱够，Alipay -商品价格\n",
    "   shopping_car。append(produce_list[user_choice])\n",
    "    else print(\"您的余额不足，请更换支付方式\")\n",
    "4.print(shopping_car)\n",
    "\n",
    "# 优化\n",
    "\n",
    "product_list = [\n",
    "    [\"IPHONE 14\",9999],\n",
    "    [\"POP MART\",89],\n",
    "    [\"NIKE\",699],\n",
    "    [\"BARBIE\",229],\n",
    "    [\"LEGO\",1299],\n",
    "]\n",
    "shopping_car = []\n",
    "\n",
    "Alipay = input(\"请输入您的支付宝余额：\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "d6f628e4",
   "metadata": {},
   "outputs": [
    {
     "ename": "IndentationError",
     "evalue": "unexpected indent (3629012753.py, line 12)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [36]\u001b[1;36m\u001b[0m\n\u001b[1;33m    for user_choice in range(1):\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mIndentationError\u001b[0m\u001b[1;31m:\u001b[0m unexpected indent\n"
     ]
    }
   ],
   "source": [
    "product_list = [\n",
    "    [\"IPHONE 14\",9999],\n",
    "    [\"POP MART\",89],\n",
    "    [\"NIKE\",699],\n",
    "    [\"BARBIE\",229],\n",
    "    [\"LEGO\",1299],\n",
    "]\n",
    "shopping_car = []\n",
    "\n",
    "Alipay = input(\"请输入余额\")\n",
    "user_choice = input(\"请输入商品编号：\")\n",
    "   \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f695b6b0",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "0bdb0cf9",
   "metadata": {},
   "outputs": [],
   "source": [
    "product_list = [\n",
    "    [\"IPHONE 14\",9999],\n",
    "    [\"POP MART\",89],\n",
    "    [\"NIKE\",699],\n",
    "    [\"BARBIE\",229],\n",
    "    [\"LEGO\",1299],\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "960dca8b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['IPHONE 14', 9999]"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "product_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "91c72a99",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "unexpected EOF while parsing (3030459667.py, line 2)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [33]\u001b[1;36m\u001b[0m\n\u001b[1;33m    print(shopping_car.append(product_list[user_choice])\u001b[0m\n\u001b[1;37m                                                        ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m unexpected EOF while parsing\n"
     ]
    }
   ],
   "source": [
    "if Alipay > user_choice:\n",
    "    print(shopping_car.append(product_list[user_choice])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8df41fd8",
   "metadata": {},
   "source": [
    "# 老师教学"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "2c5ed8eb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "for i in range(4):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "6510e860",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入余额19999\n",
      "------------商品列表--------------\n",
      "商品编号:0 ['IPHONE 14', 9999]\n",
      "商品编号:1 ['POP MART', 89]\n",
      "商品编号:2 ['NIKE', 699]\n",
      "商品编号:3 ['BARBIE', 229]\n",
      "商品编号:4 ['LEGO', 1299]\n",
      "请输入商品编号：59\n"
     ]
    },
    {
     "ename": "IndexError",
     "evalue": "list index out of range",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "Input \u001b[1;32mIn [57]\u001b[0m, in \u001b[0;36m<cell line: 11>\u001b[1;34m()\u001b[0m\n\u001b[0;32m     15\u001b[0m \u001b[38;5;66;03m# 情景一：用户输入了商品编号：shopping\u001b[39;00m\n\u001b[0;32m     16\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m user_choice\u001b[38;5;241m.\u001b[39misdigit():\n\u001b[0;32m     17\u001b[0m \u001b[38;5;66;03m# 判断钱够不够,商品价格？==》product_list[user_chioce][1]\u001b[39;00m\n\u001b[1;32m---> 18\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m Alipay \u001b[38;5;241m>\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[43mproduct_list\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;28;43mint\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43muser_chioce\u001b[49m\u001b[43m)\u001b[49m\u001b[43m]\u001b[49m[\u001b[38;5;241m1\u001b[39m]:\n\u001b[0;32m     19\u001b[0m         Alipay \u001b[38;5;241m=\u001b[39m Alipay \u001b[38;5;241m-\u001b[39m product_list[\u001b[38;5;28mint\u001b[39m(user_chioce)][\u001b[38;5;241m1\u001b[39m]\n\u001b[0;32m     20\u001b[0m         shopping_car\u001b[38;5;241m.\u001b[39mappend(product_list[\u001b[38;5;28mint\u001b[39m(user_chioce)])\n",
      "\u001b[1;31mIndexError\u001b[0m: list index out of range"
     ]
    }
   ],
   "source": [
    "product_list = [\n",
    "    [\"IPHONE 14\",9999],\n",
    "    [\"POP MART\",89],\n",
    "    [\"NIKE\",699],\n",
    "    [\"BARBIE\",229],\n",
    "    [\"LEGO\",1299],\n",
    "]\n",
    "shopping_car = []\n",
    "Alipay = int(input(\"请输入余额\"))\n",
    "while True:\n",
    "    print(\"------------商品列表--------------\")\n",
    "    for i in range(5):\n",
    "        print(\"商品编号:\" +str(i),product_list[i])\n",
    "    user_chioce = input(\"请输入商品编号：\")\n",
    "    # 情景一：用户输入了商品编号：shopping\n",
    "    if user_choice.isdigit():\n",
    "    # 判断钱够不够,商品价格？==》product_list[user_chioce][1]\n",
    "        if Alipay >= product_list[int(user_chioce)][1]:\n",
    "            Alipay = Alipay - product_list[int(user_chioce)][1]\n",
    "            shopping_car.append(product_list[int(user_chioce)])\n",
    "            print(\"您购买的商品已增加到购物车\")\n",
    "        else:\n",
    "            print(\"穷鬼！！！！\")\n",
    "    # 情景二：用户输入“q\" ，退出购买\n",
    "    elif user_chioce ==\"q\":\n",
    "        print(\"您的购物车:\",shopping_car)\n",
    "        print(\"您的余额还有：\",Alipay)\n",
    "        break\n",
    "    else:\n",
    "        print(\"您输入的商品不存在或输入有误，请重新尝试！！！\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "17387e4e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 课后作业："
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
